<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="/favicon.ico">
    <title>注册 机床故障诊断</title>
    <!-- Bootstrap core CSS -->
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <!-- Custom styles for this template -->
    <link href="/jumbotron.css" rel="stylesheet">
    <style type="text/css">
        body {
            padding-top: 120px;
        }
        #cuowukuang{
            display: none;
        }
    </style>
</head>

<body>

<div class="container">
    <!-- Example row of columns -->
    <div class="row col-lg-6">
        <h1>欢迎注册</h1>

        <form>
            <div class="form-group">
                <label for="username">用户名</label>
                <input type="text" class="form-control" id="username" placeholder="用户名，可以是中文，不能和别人重复">
            </div>
            <div class="form-group">
                <label for="password">密码</label>
                <input type="password" class="form-control" id="password" placeholder="密码，至少6位">
            </div>
            <div class="checkbox">
                <label>
                    <input type="checkbox"> 我遵守注册规定
                </label>
            </div>
            <button type="button" id="zhuce" class="btn btn-default" >注册</button>
        </form>

        <div class="alert alert-danger" role="alert" id="cuowukuang">
            用户名被占用，请更换
        </div>
    </div>
</div>

<hr>

<footer>
    <p>&copy; Company 2014</p>
</footer>
</div>
<!-- /container -->


<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="/js/jquery-1.11.3.min.js"></script>
<script src="/js/bootstrap.min.js"></script>

<script type="text/javascript">
    $("input").focus(function(){
        $("#cuowukuang").fadeOut();
    });
    $("#zhuce").click(function(){
        //注册按钮的事件，用ajax提交表单
        $.post("/doregist",{
            "username" : $("#username").val(),
            "password" : $("#password").val()
        },function(result){
            if(result == "1"){
                //注册成功
                alert("注册成功！将自动跳转到首页");
                window.location = "/";
            }else if(result == "-1"){
                //用户名被占用
                $("#cuowukuang").fadeIn();
                $("#cuowukuang").html("用户名被占用啊！");
            }else if(result == "-3"){
                //服务器错误
            }
        });
    });
</script>
</body>
</html>
